@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/admin/pagenum.css')}}" rel="stylesheet" />
    <link rel="stylesheet" href="{{url('manager/css/xadmin.css')}}">
    <script src="{{url('manager/lib/layui/layui.js')}}" charset="utf-8"></script>
    <script type="text/javascript" src="{{url('manager/js/xadmin.js')}}"></script>
@endsection

@section('html-body')
    <!-- content start -->
    <div id="content">
        <!-- cur-position start -->
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="#">用户管理</a>
            <em></em>
            <a href="#">商户列表</a>
        </div>
        <!-- cur-position end -->

        <!--二级目录-->
        @include('admin.common.user-header')

        <div class="filter-box clearfix">
            <div class="fr">
                <a class="addBtn" href="{{route('Admin.Home.managerSet')}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>用户名</th>
                    <th>角色</th>
                    <th>绑定公司</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($users) > 0)
                    @foreach($users as $a)
                        <tr id="admin_{{$a->id}}">
                            <td>{{$a->id}}</td>
                            <td>{{$a->username}}</td>
                            <td>{{$a->role_name}}</td>
                            <td>已绑定<span class="x-red">{{$a->boundCompanyShow}}{{$a->boundCompanyMany}}</span>家公司</td>
                            <td>

                                <a title="将该商户绑定到对应的公司" onclick="x_admin_show('修改/解绑公司','{{route('Admin.Home.managerBindCompany')}}?user_id={{$a->id}}')" href="javascript:;">公司绑定/解绑</a>
                                <a class="color2" href="{{route('Admin.Home.managerSet')}}?manager_id={{$a->id}}">编辑</a>

                                &nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:void(0);" class="del" data-id="{{$a->id}}">删除</a>
                            </td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
            <?php echo $users->render(); ?>
        </div>
    </div>
    <script>
        $(function(){

            $(document).on("click",".del",function(){
                var id = $(this).attr("data-id");

                noty({
                    text: '你确定要删除吗?',
                    buttons: [
                        {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                                $noty.close();
                                $.ajax({
                                    url:'{{route('Api.Admin.sys.delManagerUser')}}',
                                    type:'post',
                                    dataType:'json',
                                    data:{id:id},
                                    success:function(obj){
                                        if(obj.level == "success"){
                                            $("#admin_"+id).hide('slow');
                                        }else{
                                            noty({type:obj.level,text:obj.message,timeout:600});
                                        }
                                    },
                                    error:function(obj){
                                        console.log(obj);
                                    }

                                });
                            }
                        },
                        {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                                $noty.close();
                            }
                        }
                    ]
                });

            });
        });
    </script>
    <!-- content end -->

@endsection